package springjdbc;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class JdbcTemplateTest {

    public static void main(String args[]){
        //定义xml文件的路径
        String xmlPath = "springjdbc/beans.xml";
        //加载配置文件
        ApplicationContext ac = new ClassPathXmlApplicationContext(xmlPath);
        //获取AccountDao实例
        AccountDao accountDao = (AccountDao) ac.getBean("accountDao");
        //创建Account对象，向Account对象中添加数据
        Account account = new Account();
        account.setUsername("tom");
        account.setUsername("Jack");
        account.setBalance(1000.00);
        account.setBalance(2000.00);
//        accountDao.findAccountById(3);
//        System.out.println(account);
//        List<Account> accountList = accountDao.findAllAccount();

//        for (Account act : accountList){
//            System.out.println(act);
//        }
//        //执行addAccount方法，并获取返回结果
        int num = accountDao.addAccount(account);

        if (num > 0){
            System.out.println("成功插入了 " + num + " 条数据!");
        }
        else {
            System.out.println("插入操作执行失败！");
        }

        //执行deleteAccount方法，并获取返回结果
//        int num = accountDao.deleteAccount(1);
//
//        if (num > 0){
//            System.out.println("成功删除了" + num + " 条数据!");
//        }
//        else {
//            System.out.println("删除操作执行失败");
//        }
    }

}
